package com.xmx.ndmallwxapi.controller;

import cn.hutool.core.bean.BeanUtil;
import com.xmx.common.utils.ListFromEntity2VoUtils;
import com.xmx.common.utils.R;
import com.xmx.ndmallwxapi.feign.ProductFeignClient;
import com.xmx.ndmallwxapi.feign.PromotionFeignClient;
import com.xmx.ndmallwxapi.vo.brand.BrandHomeVo;
import com.xmx.ndmallwxapi.vo.brand.BranddetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx/brand")
public class BrandController {

    @Autowired
    ProductFeignClient productFeignClient;

    @GetMapping("/list")
    public R list(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit){
        R bdlist = productFeignClient.getBdlist(page, limit);
        List<Map> mapList = (List<Map>) ((Map)bdlist.get("data")).get("list");
        List<BrandHomeVo> brandHomeVos = ListFromEntity2VoUtils.entity2Vo(mapList, BrandHomeVo.class);
        ((Map) bdlist.get("data")).replace("list",brandHomeVos);
        return bdlist;
    }

    @GetMapping("/detail")
    public R detail(@RequestParam("id") Integer id){
        BranddetailVo brand = BeanUtil.mapToBean((Map) productFeignClient.getbrand(id).get("brand"), BranddetailVo.class, false);

        return R.ok().put("data",brand);

    }
}
